<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>定时预约是（视频）</title>
    <script src="../js/jquery-2.1.4.min.js"></script>
    <script src="../js/mui.min.js"></script>
    <link href="../css/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../css/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../css/cw.css"/>
    <script src="../js/global.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
    <script type="text/javascript" charset="UTF-8">
      	mui.init();
    </script>
    <style type="text/css">
   		.bbs-ico{padding: 10px 15px;}
   		.bbs-ico{padding-bottom:0px;position:relative;}
   		.bbs-ico{padding-bottom:5px;}
		.bbs-ico>div:nth-child(1)>i{width: 60px;display:block;float:left}
		.bbs-ico>div:nth-child(1)>i>img{border-radius:50%;height:60px;width: 100%;}
		.bbs-ico>div:nth-child(1)>div{width:calc(100% - 60px);float:left;padding-left:10px;}
		.bbs-ico>div:nth-child(1)>div>li{margin-top: 7px;}
		.mui-grid-view.mui-grid-9{background:white;}
		.mui-btn-blue{border: 1px solid #8dc21f;background-color: #8dc21f;}
    </style>
</head>
<body>
	<header id="header" class="mui-bar mui-bar-nav">
		<i class="mui-icon mui-icon-back mui-action-back"></i>
		<h1 class="mui-title ">定时预约</h1>
	</header> 
	<div id="content" class="mui-content"></div>
	<div class="table-view table-view-cell bbs-ico margin-bottom-5">
		<div class="overflow-h">
			<i><img src="../images/iconic.png" class="userPic" /></i>
			<div>
				<li>
					<span class="name"></span>&nbsp;
					<!--<span class="font-13 color-red mui-pull-right">0.0元/分钟</span>-->	
				</li>
				<li class="mui-h6 color-000">请耐心等待... ...</li>
			</div>
		</div>	
	</div>
	<div id="picture-btn" class="mui-table-view-cell mui-table-view">
		<span>已支付</span>
		<span class="mui-pull-right font-14 color-red paymoney">0.0元</span>
	</div>
	<button class="mui-btn-block rz-btn rz-btn-2">排队中...</button>

</body>

<script type="text/javascript" src="../js/jquery-2.1.4.min.js" ></script>
<script type="text/javascript" src="../js/public.js" ></script>
<script type="text/javascript">
var ws, doctorid, doctorname, doctoravatar, uid, name, avatar, money, wenzhen, spage;
var tt;
document.addEventListener('plusready', function(){
	ws = plus.webview.currentWebview();
	spage = ws.spage;
	if(spage)plus.webview.getWebviewById(spage).close();
	doctorid = ws.doctorid+"";//医生id
	doctorname = ws.doctorname;//医生名
	doctoravatar = ws.doctoravatar;//医生头像
	money = ws.money;//视频价格
	wenzhen = ws.wenzhen;//问诊记录id
	plus.nativeUI.closeWaiting();
	uid = plus.storage.getItem('uid');//当前用户id
	name = plus.storage.getItem('name');//当前用户名
	//当前用户头像。注：使用时需要判断，一般情况下需要在前面加“http://app208.51edn.com”，但该变量有"http"开头则只要直接显示
	avatar = plus.storage.getItem('avatar');
	console.log(doctorid+" "+doctorname+" "+doctoravatar+" "+uid+" "+name+" "+money);
	$('.name').text(doctorname);
	$('.userPic').attr('src', getAvatar(doctoravatar));
	$('.paymoney').text(money+"元");
	//查询在本人之前是否有人在与该医生视频
	console.log(apiRoot+"/home/chat/lineUp/uid/"+uid+"/did/"+doctorid+"/wid/"+wenzhen)
	tt = setInterval(function(){
		$.ajax({
			type:"get",
			url:apiRoot+"/home/chat/lineUp",
			data:{
				uid :uid,
				did :doctorid,
				wid :wenzhen
			},
			success :function(data){
//				mui.toast(data); 
				if(data > 0){	//有人则排队
					$('.rz-btn-2').text('排队中（'+data+'人）...');
				}else{	//发起视频
					if(avatar && avatar.indexOf('http') < 0){
						avatar = webRoot + avatar;
					}
//					mui.toast('发起视频'+doctorid+" "+name+" "+avatar+" "+wenzhen);
					clearInterval(tt);
					ws.close();
					window.plus.bridge.exec("xiangyu","sendVideo",[doctorid+'',name,avatar,wenzhen+'']);
				}
			},
			error :function(e){
				console.log(JSON.stringify(e));
			}
		});
	},5000);
},false)
</script>
</html>

